package cn.ttxs.wq.adapter;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

import cn.ttxs.lib.base.BaseFragment;

public class FragmentAdapter extends FragmentPagerAdapter {
    private List<BaseFragment> fragmentList;
    private String[] titleArr;

    public FragmentAdapter(FragmentManager fm, List<BaseFragment> fragmentList, String[] titleArr) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.fragmentList = fragmentList;
        this.titleArr = titleArr;
    }

    @Override
    public int getCount() {
        return fragmentList == null ? 0 : fragmentList.size();
    }

    @Override
    public BaseFragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titleArr[position];
    }
}
